const acl = {
    //简述acl的数据结构
    roles: [],
    users: [],
    write: false,
    read: true, 
}

export function JudgeAclWriteByRole(roleId, acl){
    return acl.roles.includes(roleId)? acl.write : true;
}

export function JudgeAclWriteByUser(userId, acl){
    return acl.users.includes(userId)? acl.write : true;
}

export function JudgeAclReadByRole(roleId, acl){
    return acl.roles.includes(roleId) ? acl.read : true;
}

export function JudgeAclReadByUser(userId, acl){
    return acl.users.includes(userId)? acl.read : true;
}

export function addRoleToAcl(roleId, acl, value, key){
    const roles = acl.roles;
    if(roles.includes(roleId)){
        acl[key]  = value;
        return acl;
    }
    roles.push(roleId);
    acl[key]  = value;
    return acl;
}

export function addUserToAcl(userId, acl, value, key){
    const users = acl.roles;
    if(users.includes(userId)){
        acl[key]  = value;
        return acl;
    }
    users.push(roleId);
    acl[key]  = value;
    return acl;
}